local scene = gamestate.new()

local ui = {
	{text = "赏金猎人",mode = "hunter"},
	{text = "穿越火线",mode = "cross"},
	{text = "基地攻略",mode = "capture"},
	{text = "最后幸存",mode = "survive"}
}

local x = 200
local y = 200
local w = 300
local h = 50
local off = 20

function scene:enter(from,game)
	self.game = game
	local sw,sh = love.graphics.getDimensions()
	x = sw*GlobalScale/2 - w/2
	self.checkCD = 1
	self.checkTimer = 0
	self.roomID = nil
	self.waiting = nil
end

function scene:update(dt)
	love.graphics.setFont(texture.font)
	self.checkTimer = self.checkTimer - dt
	if self.waiting then
		suit.Label(self.waiting,x,y-100,w,h)
		if self.checkTimer<0 and self.roomID then
			self.checkTimer = self.checkCD
			net.client:send("need_room_info",{id = self.roomID})
		end
	else
		suit.Label("选择房间类型",x,y-100,w,h)
		local offy = 0
		for i = 1,4 do
		    local b = ui[i]
		    local r = suit.Button(b.text,b,x,y+offy,w,h)
		    if r.entered then
		        sound:play("hover")
		    end
		    if r.hit then
				net.client:send("create_room",{mode = b.mode})
		    end
			offy = offy + (h + off)
		end
	end
  	self.game:update(dt)
end

function scene:setWaiting(room)
	if not self.roomID then
		self.roomID = room.id
		net.client:send("join_room",{id = room.id})
	end
	self.waiting = string.format("等待其他玩家\n(%d-%d/%d)",room.playerCount,room.min,room.max)
end

function scene:draw()
	self.game:draw()
	suit.draw()
end

function scene:keypressed(k)
	if k == "escape" then
		gamestate.switch(gameState.title)
	end
end

return scene